package org.malred.hospital.controller;

import org.malred.hospital.common.R;

import org.malred.hospital.entity.TbHistory;
import org.malred.hospital.entity.TbHistory;
import org.malred.hospital.entity.TbHistory;
import org.malred.hospital.service.HistoryService;
import org.malred.hospital.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//@CrossOrigin(origins = "*",maxAge = 3600)
@RestController
@RequestMapping("/history")
public class HistoryController extends BaseController<TbHistory> {
    @Autowired
    private HistoryService service;

    @Override
    public R<List<TbHistory>> findAll() {
        return R.success(service.list());
    }

    @Override
    public R<TbHistory> findById(Long id) {
        return R.success(service.getById(id));
    }

    @Override
    public R<TbHistory> insert(@RequestBody TbHistory dto) {
        if (service.save(dto)) {
            return R.success(dto);
        } else {
            return R.error("添加 [History] 失败");
        }
    }

    @Override
    public R<TbHistory> update(@RequestBody TbHistory dto) {
        if (service.save(dto)) {
            return R.success(dto);
        } else {
            return R.error("修改 [History] 失败");
        }
    }

    @Override
    public R<TbHistory> delete(Long id) {
        if (service.removeById(id)) {
            return R.success(null);
        } else {
            return R.error("删除 [History] 失败");
        }
    }
}
